home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / libkb100.zip / LIBKB-1.00 / INCLUDE / KB.H next >
C/C++ Source or Header  |  1996-07-23  |  15KB  |  386 lines

  1. /* kb.h -- interface of the 'libkb' keyboard library
  2.   version 1.00, 23 Jul 1996.
  3.  
  4.   Copyright (C) 1995, 1996 Markus Franz Xaver Johannes Oberhumer
  5.  
  6.   This software is provided 'as-is', without any express or implied
  7.   warranty.  In no event will the authors be held liable for any damages
  8.   arising from the use of this software.
  9.  
  10.   Permission is granted to anyone to use this software for any purpose,
  11.   including commercial applications, and to alter it and redistribute it
  12.   freely, subject to the following restrictions:
  13.  
  14.   1. The origin of this software must not be misrepresented; you must not
  15.      claim that you wrote the original software. If you use this software
  16.      in a product, an acknowledgment in the product documentation would be
  17.      appreciated but is not required.
  18.   2. Altered source versions must be plainly marked as such, and must not be
  19.      misrepresented as being the original software.
  20.   3. This notice may not be removed or altered from any source distribution.
  21.  
  22.   Markus F.X.J. Oberhumer
  23.   markus.oberhumer@jk.uni-linz.ac.at
  24.  */
  25.  
  26.  
  27. #ifndef __LIBKB_KB_H
  28. #define __LIBKB_KB_H
  29.  
  30. #define KB_LIBKB            KB_VERSION_ID
  31.  
  32. #define KB_VERSION_ID       0x1000          /* version + patchlevel */
  33. #define KB_VERSION_STRING   "1.00"
  34. #define KB_VERSION_DATE     "23 Jul 1996"
  35.  
  36. #if defined(MSDOS) || defined(__MSDOS__) || defined(__EMX__)
  37. #  define __KB_MSDOS
  38. #  if defined(__32BIT__) || defined(__FLAT__) || defined(__GNUC__)
  39. #    define __KB_MSDOS32
  40. #  else
  41. #    define __KB_MSDOS16
  42. #  endif
  43. #elif defined(__linux__) && defined(__GNUC__)
  44. #  define __KB_LINUX
  45. #  define __KB_UNIX
  46. #else
  47. #  error unsupported compiler
  48. #endif
  49.  
  50.  
  51. #if defined(__KB_MSDOS)
  52. #  include <conio.h>
  53. #endif
  54.  
  55. #ifdef __cplusplus
  56. extern "C" {
  57. #endif
  58.  
  59.  
  60. /* utility macros for bits accessing */
  61. #define KB_ALL_MASK(x,mask)         (((x) & (mask)) == (mask))
  62. #define KB_ANY_MASK(x,mask)         (((x) & (mask)) != 0)
  63. #define KB_NO_MASK(x,mask)          (((x) & (mask)) == 0)
  64.  
  65.  
  66. /***********************************************************************
  67. // keyboard access
  68. ************************************************************************/
  69.  
  70. /* installation of keyboard handler */
  71. int kb_install(unsigned long flags);    /* install keyboard handler */
  72. void kb_remove(void);                   /* remove keyboard handler */
  73. #define kb_flags()                  ((unsigned long) _kb_flags)
  74. #define kb_mode()                   ((int) _kb_mode)
  75.  
  76. /* update the keyboard - needed under Linux */
  77. void kb_update(void);
  78.  
  79. /* access all keys */
  80. #define kb_key(scan)                ((unsigned char) _kb_key[scan])
  81. #define kb_keys_pressed()           ((int) _kb_keys_pressed)
  82. #define kb_last_key()               ((unsigned short) _kb_last_key)
  83. #define kb_shift()                  ((unsigned short) _kb_shift)
  84.  
  85. #define kb_last_key_set(k)          ((void) (_kb_last_key = (k)))
  86. #define kb_shift_off(s)             ((void) (_kb_shift &= ~(s)))
  87. #define kb_shift_on(s)              ((void) (_kb_shift |= (s)))
  88.  
  89. /* read a single keypress */
  90. unsigned kb_keypress(void);         /* basic access function */
  91. unsigned long kb_inkey(void);       /* full info keypress */
  92. unsigned kb_getkey(void);           /* compatible to getkey() */
  93. int kb_kbhit(void);                 /* compatible to kbhit() */
  94.  
  95.  
  96. /* you are allowed to modify the following variables */
  97. extern volatile unsigned short _kb_shift;   /* current shift state */
  98. extern volatile unsigned short _kb_last_key;/* last key pressed */
  99.  
  100. /* these are READ ONLY - use the access-macros above */
  101. extern volatile unsigned char _kb_key[128]; /* the key flags */
  102. extern volatile int _kb_keys_pressed;       /* number of keys pressed */
  103. extern unsigned long _kb_flags;             /* flags after kb_install() */
  104. extern int _kb_mode;                        /* do we have a keyboard handler? */
  105.  
  106.  
  107. /***********************************************************************
  108. // flags - kb_install() and kb_flags()
  109. // note: the only flag you probably need is emergency exit
  110. ************************************************************************/
  111.  
  112. /* pass these to kb_install() */
  113. #define KB_FLAG_NO_ATEXIT           0x0001   /* do not use atexit() */
  114. #define KB_FLAG_NO_SIGNAL           0x0002   /* do not install signal handler */
  115. #define KB_FLAG_NO_LOCK             0x0004   /* do not lock memory */
  116. #define KB_FLAG_SIGINT              0x0010   /* raise SIGINT on Control-C */
  117. #define KB_FLAG_EMERGENCY_EXIT      0x0020   /* enable emergency exit */
  118. #define KB_FLAG_EMERGENCY_SIGALRM   0x0040   /* enable SIGALRM emergency */
  119. #define KB_FLAG_LINUX_NO_VT         0x0100   /* no virtual term switching */
  120. #define KB_FLAG_LINUX_VT_NO_KEY     0x0200   /* release all keys after VT */
  121. #define KB_FLAG_DJGPP_NO_RM         0x0400   /* no real-mode handler */
  122. #define KB_FLAG_REPEAT_OFF          0x1000   /* turn off key repeat */
  123.  
  124. /* these information bits are set by kb_install() but do not cause an error */
  125. #define KB_FLAG_ATEXIT_FAILED   0x00010000L  /* error atexit() */
  126. #define KB_FLAG_SIGNAL_FAILED   0x00020000L  /* error installing signals */
  127. #define KB_FLAG_LOCK_FAILED     0x00040000L  /* error while locking memory */
  128.  
  129. /* these information bits are set by kb_install() */
  130. #define KB_FLAG_ATEXIT_DONE     0x00100000L  /* atexit() was called */
  131. #define KB_FLAG_SIGNAL_DONE     0x00200000L  /* signal handler installed */
  132. #define KB_FLAG_LOCK_DONE       0x00400000L  /* memory was locked */
  133.  
  134.  
  135. /***********************************************************************
  136. // keyboard scan codes - kb_key()
  137. // 1-88,96-111 are fairly standard and should probably not be changed
  138. ************************************************************************/
  139.  
  140. /* get the name of a key */
  141. const char *kb_keyname(int scan);
  142.  
  143. /* raw keys 1-88, 87 keys */
  144. #define KB_SCAN_ESC             1
  145. #define KB_SCAN_1               2 
  146. #define KB_SCAN_2               3 
  147. #define KB_SCAN_3               4
  148. #define KB_SCAN_4               5
  149. #define KB_SCAN_5               6
  150. #define KB_SCAN_6               7
  151. #define KB_SCAN_7               8
  152. #define KB_SCAN_8               9
  153. #define KB_SCAN_9               10
  154. #define KB_SCAN_0               11
  155. #define KB_SCAN_MINUS           12
  156. #define KB_SCAN_EQUAL           13
  157. #define KB_SCAN_BACKSPACE       14
  158. #define KB_SCAN_TAB             15 
  159. #define KB_SCAN_Q               16
  160. #define KB_SCAN_W               17
  161. #define KB_SCAN_E               18
  162. #define KB_SCAN_R               19
  163. #define KB_SCAN_T               20
  164. #define KB_SCAN_Y               21
  165. #define KB_SCAN_U               22
  166. #define KB_SCAN_I               23
  167. #define KB_SCAN_O               24
  168. #define KB_SCAN_P               25
  169. #define KB_SCAN_OPENBRACE       26
  170. #define KB_SCAN_CLOSEBRACE      27
  171. #define KB_SCAN_ENTER           28
  172. #define KB_SCAN_LCONTROL        29    /* Left Control */
  173. #define KB_SCAN_A               30
  174. #define KB_SCAN_S               31
  175. #define KB_SCAN_D               32
  176. #define KB_SCAN_F               33
  177. #define KB_SCAN_G               34
  178. #define KB_SCAN_H               35
  179. #define KB_SCAN_J               36
  180. #define KB_SCAN_K               37
  181. #define KB_SCAN_L               38
  182. #define KB_SCAN_COLON           39
  183. #define KB_SCAN_QUOTE           40
  184. #define KB_SCAN_BACKQUOTE       41
  185. #define KB_SCAN_LSHIFT          42    /* Left Shift */
  186. #define KB_SCAN_BACKSLASH       43
  187. #define KB_SCAN_Z               44
  188. #define KB_SCAN_X               45
  189. #define KB_SCAN_C               46
  190. #define KB_SCAN_V               47
  191. #define KB_SCAN_B               48
  192. #define KB_SCAN_N               49
  193. #define KB_SCAN_M               50
  194. #define KB_SCAN_COMMA           51
  195. #define KB_SCAN_PERIOD          52
  196. #define KB_SCAN_SLASH           53
  197. #define KB_SCAN_RSHIFT          54    /* Right Shift */
  198. #define KB_SCAN_MULTIPLY_PAD    55
  199. #define KB_SCAN_ALT             56    /* Left Alt */
  200. #define KB_SCAN_LALT            KB_SCAN_ALT
  201. #define KB_SCAN_SPACE           57
  202. #define KB_SCAN_CAPSLOCK        58
  203. #define KB_SCAN_F1              59
  204. #define KB_SCAN_F2              60
  205. #define KB_SCAN_F3              61
  206. #define KB_SCAN_F4              62
  207. #define KB_SCAN_F5              63
  208. #define KB_SCAN_F6              64
  209. #define KB_SCAN_F7              65
  210. #define KB_SCAN_F8              66
  211. #define KB_SCAN